package com.ruoyi.web.controller.violation;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.dto.MapDto;
import com.ruoyi.system.util.BaiDuMapUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.violation.domain.ConstructionSiteCheckReport;
import com.ruoyi.violation.service.IConstructionSiteCheckReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目巡查记录Controller
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@RestController
@RequestMapping("/violation/check")
public class ConstructionSiteCheckReportController extends BaseController
{
    @Autowired
    private IConstructionSiteCheckReportService constructionSiteCheckReportService;

    /**
     * 查询项目巡查记录列表
     */
    @PreAuthorize("@ss.hasPermi('violation:check:list')")
    @GetMapping("/list")
    public AjaxResult list(ConstructionSiteCheckReport constructionSiteCheckReport)
    {
        List<ConstructionSiteCheckReport> list = constructionSiteCheckReportService.selectConstructionSiteCheckReportList(constructionSiteCheckReport);
        return AjaxResult.success(list);
    }
    /**
     * 分页查询项目巡查记录列表
     */
    @PreAuthorize("@ss.hasPermi('violation:check:list')")
    @GetMapping("page")
    public TableDataInfo page(ConstructionSiteCheckReport constructionSiteCheckReport)
    {
        startPage();
        List<ConstructionSiteCheckReport> list = constructionSiteCheckReportService.selectConstructionSiteCheckReportList(constructionSiteCheckReport);
        return getDataTable(list);
    }

    /**
     * 导出项目巡查记录列表
     */
    @PreAuthorize("@ss.hasPermi('violation:check:export')")
    @Log(title = "项目巡查记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConstructionSiteCheckReport constructionSiteCheckReport)
    {
        List<ConstructionSiteCheckReport> list = constructionSiteCheckReportService.selectConstructionSiteCheckReportList(constructionSiteCheckReport);
        ExcelUtil<ConstructionSiteCheckReport> util = new ExcelUtil<ConstructionSiteCheckReport>(ConstructionSiteCheckReport.class);
        util.exportExcel(response, list, "项目巡查记录数据");
    }

    /**
     * 获取项目巡查记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('violation:check:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(constructionSiteCheckReportService.selectConstructionSiteCheckReportById(id));
    }

    /**
     * 新增项目巡查记录
     */
    @PreAuthorize("@ss.hasPermi('violation:check:add')")
    @Log(title = "项目巡查记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConstructionSiteCheckReport constructionSiteCheckReport)
    {
        constructionSiteCheckReport.setReportNumber("PCR"+System.currentTimeMillis());
        String lat = constructionSiteCheckReport.getLat();
        String lon = constructionSiteCheckReport.getLon();
        MapDto mapDto = new MapDto();
        mapDto.setLat(lat);
        mapDto.setLon(lon);
        String address = BaiDuMapUtil.getAddress(mapDto);
        constructionSiteCheckReport.setAddress(address);
        constructionSiteCheckReport.setLawUserId(getUserId());
        constructionSiteCheckReport.setLawUserName(getUsername());
        return toAjax(constructionSiteCheckReportService.addJoin(constructionSiteCheckReport));
    }

    /**
     * 修改项目巡查记录
     */
    @PreAuthorize("@ss.hasPermi('violation:check:edit')")
    @Log(title = "项目巡查记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstructionSiteCheckReport constructionSiteCheckReport)
    {
        String lat = constructionSiteCheckReport.getLat();
        String lon = constructionSiteCheckReport.getLon();
        MapDto mapDto = new MapDto();
        mapDto.setLat(lat);
        mapDto.setLon(lon);
        String address = BaiDuMapUtil.getAddress(mapDto);
        constructionSiteCheckReport.setAddress(address);
        return toAjax(constructionSiteCheckReportService.updateConstructionSiteCheckReport(constructionSiteCheckReport));
    }

    /**
     * 删除项目巡查记录
     */
    @PreAuthorize("@ss.hasPermi('violation:check:remove')")
    @Log(title = "项目巡查记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(constructionSiteCheckReportService.deleteConstructionSiteCheckReportByIds(ids));
    }
}
